// https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html
import React from 'react';


class Child extends React.Component {

  constructor(props) {
    super(props);
    this.state = {}
  }

  /** 实例化开始  */
  // getDefaultProps was defined on Child, a plain JavaScript class. This is only supported for classes created using React.createClass
  // getDefaultProps() {
  //   console.log('Child: getDefaultProps')
  // }

  // getInitialState was defined on Child, a plain JavaScript class. This is only supported for classes created using React.createClass.
  // getInitialState() {
  //   console.log('Child: getInitialState')
  // }

  // UNSAFE_componentWillMount() {
  //   console.log('Child: UNSAFE_componentWillMount')
  // }

  render() {
    console.log('Child: render')
    return (
      <h3>{this.props.name}</h3>
    )
  }

  componentDidMount() {
    console.log('Child: componentDidMount')
  }

  /** 实例化结束 */

  /** 更新时 开始 */

  // this new lifecycle should cover all use cases for the legacy componentWillReceiveProps.
  static getDerivedStateFromProps(props, state) {
    console.log('Child: getDerivedStateFromProps')
    return null;
  }

  // UNSAFE_componentWillReceiveProps() {
  //   console.log('Child: UNSAFE_componentWillReceiveProps')
  // }

  shouldComponentUpdate() {
    console.log('Child: shouldComponentUpdate')
  }

  // this new lifecycle should cover all use cases for the legacy componentWillUpdate
  getSnapshotBeforeUpdate(prevProps, prevState) {
    console.log('Child: getSnapshotBeforeUpdate')
  }

  // UNSAFE_componentWillUpdate() {
  //   console.log('Child: UNSAFE_componentWillUpdate')
  // }

  // 此处会再调用楼上的 render代码进行渲染

  componentDidUpdate() {
    console.log('Child: componentDidUpdate')
  }
  /** 更新时 结束 */

  /** 组件销毁前 */
  componentWillUnmount() {
    console.log('Child: componentWillUnmount')
  }
}

export default Child